#ifndef __CASE_TPL_SINGLETON_H__
#define __CASE_TPL_SINGLETON_H__

#include "../case_base.h"
#include "basic/tpl_singleton.h"

class TestSingleton final : public tpl_Singleton<TestSingleton> {
  M_SINGLETON_DECLEAR(TestSingleton)
public:
  int GetInt() {
    return 3;
  }

private:
  void Init() override {
    cout << "singleton Init" << endl;
  }
  void DeInit() override {
    cout << "singleton DeInit" << endl;
  }
};

class TestSingleton_no_override final
    : public tpl_Singleton<TestSingleton_no_override> {
  M_SINGLETON_DECLEAR(TestSingleton_no_override)
public:
  int GetInt() {
    return 40;
  }
};

class Test_tpl_singleton : public CaseBase {
public:
  Test_tpl_singleton() {
  }
  ~Test_tpl_singleton() {
  }
  void Init() override {
    m_sCaseName = "test tpl_singleton.h";
  }
  void DeInit() override {
  }
  void Test() override {
    // TestSingleton* ins=new TestSingleton(); // this is wrong:
    TestSingleton* insa = TestSingleton::GetIns();
    TestSingleton* insb = TestSingleton::GetIns();
    assert(insa == insb); // same addr.

    TestSingleton_no_override* ins2 = TestSingleton_no_override::GetIns();
    assert(ins2->GetInt() == 40);
  }
};

#endif
